<?php
include_once('session_clientes.php');
$accion = "ADD";
require_once('php/class/clientes.class.php');
$id_cliente = $_SESSION['id_cliente'];
$oCliente = new cliente();
$oCliente->search($id_cliente);
?>
<html>
  <?php include('include.header.html'); ?>
  <body class="bodycliente">
    <form id="frm_bp" name="frm_bp" method="post">

      <input type="hidden" id="id" name="id" value="<?php echo $id_cliente; ?>">

      <div id="usuario" align="center">

        <table class="marco">
          <tr>
            <td height="10%">
              <?php include('menu_clientes.php'); ?>
            </td>
          </tr>
          <tr>
            <td align="left" valign="top">
              <table width="80%" border="0">
                <tr>
                  <td rowspan="2" width="110">&nbsp;</td>
                  <td valign="top" width="100"> 
                    <table border="0" class="boton" width="100%">
                      <tr>
                        <td><a href='modificar_datos_clientes.php'>Mis Datos</a></td>
                      </tr>
                    </table>
                  </td>
                  <td valign="top" width="100"> 
                    <table border="0" class="boton" width="100%">
                      <tr>
                        <td><a href='cambio_clave_cliente.php'><u>Cambiar clave</u></a></td>
                      </tr>
                    </table>
                  </td>
                  <td valign="top" width="100"> 
                    <table border="0" class="boton" width="100%">
                      <tr>
                        <td><a href='carrito_clientes.php'>Mi Carrito</a></td>
                      </tr>
                    </table>
                  </td>
                  <td valign="top" width="100"> 
                    <table border="0" class="boton" width="100%">
                      <tr>
                        <td><a href='mis_compras_clientes.php'>Mis Compras</a></td>
                      </tr>
                    </table>
                  </td>
                  <td>&nbsp;</td>
                  </td>
                </tr>
                <tr>
                  <td colspan="5"> 
                    <div id="DATO_HIDE" style="display:none" style="width:90%">
                      <div id="DATO" class="mensajes">&nbsp;</div>
                    </div>
                    <table class="formulario" width="100%">
                      <tr>
                        <td>Ingrese la clave actual</td>
                        <td><input type="password" id="actual" name="actual" class="validate['required','length[6,10]']"></td>
                      </tr>
                      <tr>
                        <td>Ingrese la nueva clave</td>
                        <td><input type="password" id="nueva" name="nueva" class="validate['required','length[6,10]']"></td>
                      </tr>
                      <tr>
                        <td>Confirme la nueva clave</td>
                        <td><input type="password" id="r_nueva" name="r_nueva" class="validate['confirm[nueva]']"></td>
                      </tr>
                      <tr>
                        <td align="right">
                          <input type="button" value="Cancelar">
                        </td>
                        <td align="left">
                          <input type="submit" id="submit" name="submit" value="Guardar">
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>           
            </td>
          </tr>
          <tr>
            <td height="10%" valign="bottom" align="center">
              <?php include('footer.php'); ?>
            </td>
          </tr>
        </table>

      </div>
    </form>
  </body>
  <?php include('include.footer.html'); ?>
  <script>
    ///////////////////////////////
    var myCheck;
    myCheck = new FormCheck('frm_bp', {
      submit:false,
      display:{
        errorsLocation : 1,
        indicateErrors : 2,
        keepFocusOnError : 0,
        closeTipsButton : 1,
        checkValueIfEmpty:1,                
        showErrors : 1
      }
    });		 
 
    $('frm_bp').addEvent('submit',function(ev){
      var IsValid;
      IsValid=myCheck.isFormValid();                                                                          
      if (IsValid){ 
            
        Ejecutor();
      }    
    });
    ///////////////////////////////

    function Ejecutor(){        
      window.addEvent('domready', function() {      	       
        var req = new Request.JSON({
          method: 'POST',
          url: 'ajax/ajax_cambio_clave_clientes.php', 
          data: $('frm_bp'),                
          noCache:true,                     
          onRequest: function(){
            $('submit').disabled = true;
            $('DATO_HIDE').show();
//            $('DATO').innerHTML = 'Procesando ...'; 
          },
          onComplete: function(){
            setTimeout(function(){
              $('DATO_HIDE').fade('out').get('tween').chain(function() {
                $('DATO_HIDE').hide();
                $('DATO_HIDE').fade('in');                                                         
              });
            },2000);                                                                                                                                                                                                              
          },             
          onSuccess: function(response){
            switch(parseInt(response.RESULT)){
              case 0:
                $('DATO').innerHTML = "Operaci&oacute;n exitosa";  
                window.location='cambio_clave_clientes_respuesta.php';
                break;
              case 1:
                $('DATO').innerHTML = response.ERROR;
                $('submit').disabled = false;
                break;
            }
          }
        }).get();        
      });
    }
  </script>
</html>
